package com.foreknow.demo5;

import java.util.Scanner;

public class Manager {

    //登录(根据用户和密码)
    public static boolean login(String username,String password) {
        //select * from user where username=? and password=?
        return true;
    }

    //注册(填写用户用户和密码) insert into user(username,password) values(?,?)
    public static boolean register(String username,String password) {
        return true;
    }



    //根据id删除用户   delete from user where id=?
    public static boolean deleteById(int id) {
        return false;
    }

    //根据id查询用户名  select username from user where id=?
    public static String getQueryByIdName(int id) {
        Scanner input = new Scanner(System.in);
        String username = input.next();
        return username;
    }

    //修改用户信息(修改用户名和密码) update user set username=? where id = ?
    public static int update(String username) {
        return 1;
    }

    //查询所有用户信息（用户名）  select username from user
    public static String[] getQueryByNames() {
        String[] array = new String[10];
        array[0] = "tom";
        array[1] = "blues";
        return array;
    }

    public static void main(String[] args) {

        //将调用方法的返回结果赋值给arr变量
        String[] arr = Manager.getQueryByNames();
        //遍历输出数组中的数据
        for(int i = 0;i<arr.length;i++){
            System.out.println(arr[i]);
        }


        //修改用户信息
        // 1. 先根据id查询到用户的信息
        String username = Manager.getQueryByIdName(1);
        // 2. 修改用户信息
        int isRight = Manager.update(username);
        if(isRight==1) {
            System.out.println("success......");
        }else {
            System.out.println("error......");
        }



        //        Scanner input = new Scanner(System.in);
        //        System.out.println("请输入用户名: ");
        //        String username = input.next();
        //        int str = 12;
        String name = Manager.getQueryByIdName(1);
        System.out.println(name);


//        Scanner input = new Scanner(System.in);
//        System.out.println("请输入用户名: ");
//        String username = input.next();
//        System.out.println("请输入密码: ");
//        String password = input.next();
//        boolean isRight = Manager.login(username,password);
//        if(isRight) {
//            System.out.println("登录成功......");
//        }else {
//            System.out.println("登录失败......");
//        }

    }

}
